﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace NetVoxLab.Framework
{
    public static class Utilities
    {
        public static object GetPropValue(string property, object obj)
        {
            if (obj == null)
                return null;

            if (string.IsNullOrEmpty(property))
                return null;

            Type type = obj.GetType();
            PropertyInfo info = type.GetProperty(property, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            if (info == null)
                return null;

            return info.GetValue(obj, null);
        }

        /// <summary>
        /// Remove special chars from source
        /// </summary>
        /// <param name="source">Source text file</param>
        /// <returns>Source without special chars</returns>
        public static string RemoveSpecialChars(string source)
        {
            // todo refactor it - use regex
            if (string.IsNullOrEmpty(source))
                return string.Empty;

            string output = source.Trim();
            output = output.Replace("\n", " ");
            output = output.Replace("\r", " ");
            output = output.Replace("\t", " ");

            return output;
        }
    }
}
